import {
  observable,
  action,
} from 'mobx';
// import axios from 'axios';

export default class AppState {
  constructor({ count, name, ports } = { count: 0, name: 'zhuxiaohui', ports: [] }) {
    this.name = name;
    this.count = count;
    this.ports = ports;
  }
  @observable count;
  @observable name;
  @observable ports;
  @action changeName(name) {
    this.name = name;
  }
  @action getPorts(args) {
    this.ports = args;
    // return new Promise((resolve, reject) => {
    //   axios.post('http://192.168.30.166:8889/c/orders/base/basicEnum', {}).then(res => {
    //     if (res.status === 200 && res.data.msg === 'success') {
    //       this.ports.push(res.data.data);
    //     }
    //     resolve(true);
    //   }).catch(err => {
    //     reject(err)
    //   })
    // })
  }
  toJson() {
    return {
      count: this.count,
      name: this.name,
      ports: this.ports,
    }
  }
}
